#!/usr/bin/python3

import mysql.connector
print('''Content-Type: text/html

<!DOCTYPE html>
<html>
<head>
<title>Dynamic Webpage Test</title>
</head>
<body>
<h2>Employee Table</h2>
<table border=1>
<tr><th>EmpID</th><th>Last Name</th><th>First Name</th><th>Salary</th></tr>''')

conn = mysql.connector.connect(user='test', password='test', database='pytest')
cursor = conn.cursor()

query = ('SELECT empid, lastname, firstname, salary FROM employees')
cursor.execute(query)
for (empid, lastname, firstname, salary) in cursor:
    print('<tr><td>', empid, '</td>')
    print('<td>', lastname, '</td>')
    print('<td>', firstname, '</td>')
    print('<td>', salary, '</td></tr>')
print('</table>')
print('</body>')
print('</html>')
cursor.close()
conn.close()
